package com.wangyg.juc.BreadMaker;

import java.util.concurrent.BlockingQueue;

/**
 * Created by wangyg6 on 2018/7/10.
 */
public class Buyer implements Runnable {
	BlockingQueue<Integer> bq;

	public Buyer setBq(BlockingQueue<Integer> bq) {
		this.bq = bq;
		return this;
	}

	@Override
	public void run() {
		Integer bread;
		String name = Thread.currentThread().getName();
		while (true) {
			try {
				Thread.sleep((long) (Math.random() * 200));
				bread = bq.take();
				System.out.println(name + "：买了第" + bread + "个面包");
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
}
